<?php

namespace App\Http\Requests;


/**
 * 用户Request验证类
 * Class UserRequest
 * @package App\Http\Requests
 */
class UserRegisterRequest extends BaseRequest
{
    /**
     * 这个地方记得为 true, 默认为 false 会返回 403 未授权提示
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     * @return string[]
     */
    public function rules()
    {
        return [
            'phone'                 => 'required|unique:users,phone',
            'password'              => 'required|between:6,32|confirmed' ,
            'password_confirmation' => 'required|same:password' ,
            'nickname'              => 'required|min:2|max:32|unique:users,nickname' ,
        ];
    }

    /**
     * 验证不通过提示
     * @return string[]
     */
    public function messages()
    {
        return [
            'phone.required' => '请输入手机号' ,
            'phone.regex'    => '手机号格式错误' ,
            'phone.unique'   => '手机号已存在' ,

            'password.required'              => '请输入密码' ,
            'password.between'               => '密码长度在6到32位之间' ,
            'password.confirmed'             => '请输入确认密码' ,
            'password_confirmation.required' => '请输入确认密码' ,
            'password_confirmation.same'     => '两次密码不一致' ,

            'nickname.required'  => '请输入姓名' ,
            'nickname.min'       => '姓名字数范围在2到20之间' ,
            'nickname.max'       => '姓名字数范围在2到20之间' ,
            'nickname.unique'    => '姓名已存在' ,
        ];
    }

}
